package collection01;
import java.util.Collection;
import java.util.HashSet;
import java.util.Arrays;
import java.util.ArrayList;
public class CollectionDemo1 {
    public static void main(String[] args) {
        Collection c = new ArrayList();
        //Collection c = new HashSet();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");

        boolean b = c.add("one");//add()的返回值为boolean型, 添加成功返回true, 否则返回false
        System.out.println(b);//true

        //集合重写了Object类的toString()方法, 返回格式如下:
        //[元素1.toString(), 元素2.toSting(), 元素3.toString(),...]
        System.out.println(c);//[one, two, three, four, five]

        System.out.println("size: "+c.size());//5, 输出集合的元素个数
        System.out.println("是否是空集: "+c.isEmpty());//false, 只有当size()为0是表示为空集
        c.clear();//清空集合
        System.out.println("集合已清空!");
        System.out.println(c);
        System.out.println("size: "+c.size());//0
        System.out.println("是否是空集:"+c.isEmpty());//true
    }

}
